package com.chihsien.springcloud.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;

/**
 * @auther chihsien on 2021/5/31
 */
@Component
@EnableBinding(Sink.class) //sink接收端的流 即消费者
public class ReceiveMessageListener
{
    @Value("${server.port}")
    private String serverPort;//获取端口编号

    @StreamListener(Sink.INPUT)//监听Sink.INPUT
    public void input(Message<String> message)
    {
        //Source用的withPayload发送 这边拿getPayload接收
        System.out.println("消费者1号，------->接收到的消息：" + message.getPayload()+"\t port: "+serverPort);
    }
}

